/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.logic.facade;
import com.edu.kamai.exception.*;
import com.edu.kamai.persistence.beans.User;
import com.edu.kamai.persistence.dao.UserDAO;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class UserFacade {
    public static int register(User usrBean) throws UserRegisterFailException{
        UserDAO usrdao = new UserDAO();
        User usr = usrdao.findUser(usrBean.getUserId());
        // user already exist, register failed.
        if(null != usr ){
            return 0;
            //throw new UserRegisterFailException("UserId: " + usrBean.getUserId() + " already exist, register failed.");
        }
        usrdao.addUsr(usrBean);
        return 1;
    }
    
    public static int login(String usrID,String usrPwd,int role) {
        UserDAO usrdao = new UserDAO();
        User usr = usrdao.chkUsrValid(usrID, usrPwd,role);
        return usr == null? 0:1;
    }
    
    public static List<User> chekPendingList(){
        UserDAO usrdao = new UserDAO();
        return usrdao.chekPendingList();
    }
    
    public static int validateUsr(String usrID){
        UserDAO usrdao = new UserDAO();
        User user = usrdao.findUser(usrID);
        if(null == user){
            return 0;
        }
        user.setStatus(1);
        usrdao.updateUsr(user);
        return 1;      
    }
}
